package com.nchu.ft.controller;


import com.nchu.ft.common.domain.ApiResult;
import com.nchu.ft.entity.Branch;
import com.nchu.ft.service.BranchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: BranchController
 * @description:
 * @Author: Chuanwei Li
 * @CreateTime: 2025-08-17 15:53
 * @Version: 1.0
 */
@RestController
@RequestMapping("/branch")
public class BranchController {
    @Autowired
    private BranchService<Branch> branchService;

    @PostMapping("/addBranch")
    public ApiResult<Boolean> addBranch(Branch branch) {
        return ApiResult.success(branchService.save(branch));
    }

    @PostMapping("/updateBranch")
    public ApiResult<Boolean> updateBranch(Branch branch) {
        return ApiResult.success(branchService.updateById(branch));
    }

    @PostMapping("/deleteBranch")
    public ApiResult<Boolean> deleteBranch(Integer id) {
        return ApiResult.success(branchService.removeById(id));
    }

    @GetMapping("/getBranchById")
    public ApiResult<Branch> getBranch(@RequestParam("branchId") Integer branchId) {
        return ApiResult.success(branchService.getById(branchId));
    }

    @GetMapping("/getBranchList")
    public ApiResult<List<Branch>> getBranchList() {
        return ApiResult.success(branchService.list());
    }
}
